﻿using System;
using System.Collections.Generic;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media;
namespace TciNewsReader_2014_04.Converters
{
    /// <summary>
    /// Provide a simple mechanism to rotate among several colours
    /// </summary>
    public sealed class ColourIncrementer : MarkupExtension, IValueConverter
    {
        private static int _count;
        private static readonly List<SolidColorBrush> Brushes;
        static ColourIncrementer()
        {
            _count = 0;
            Brushes = new List<SolidColorBrush> {System.Windows.Media.Brushes.CadetBlue, System.Windows.Media.Brushes.DeepSkyBlue, System.Windows.Media.Brushes.DodgerBlue};
        }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            ++_count;
            if (_count >= Brushes.Count)
            {
                _count = 0;
            }
            return Brushes[_count];
        }
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}
